<template>
  <div class="container">
    <div class="close">
      <span class="iconfont iconicon-test"></span>
    </div>
    <div class="logo">
      <span class="iconfont iconnew"></span>
    </div>
    <div class="inputs">
      <!-- <input placeholder="手机号码" class="input" />
      <input placeholder="昵称" type="password" />-->

      <hm_input
        type="text"
        v-model.trim="user.username"
        placeholder="请输入用户名"
        :rules="/^(\d{5,6})$|^(1\d{10})$/"
        msg="用户名或者手机号输入不正确"
      ></hm_input>
      <hm_input type="text" v-model.trim="user.nickname" placeholder="请输入昵称"></hm_input>
      <hm_input
        type="password"
        v-model.trim="user.password"
        placeholder="请输入密码"
        :rules="/^\S{3,16}$/"
        msg="请输入3-16位的密码"
      ></hm_input>
    </div>
    <p class="tips">
      有账号？
      <a href="#/login" class>去登录</a>
    </p>
    <!-- <div class="button">注册</div> -->
    <hm_button type="success" @click="register">注册</hm_button>
  </div>
</template>

<script>
import hm_button from "@/components/hm_button.vue";
import hm_input from "@/components/hm_input.vue";
import { userRegister } from "@/apis/user.js";
export default {
  components: {
    hm_button,
    hm_input
  },
  data() {
    return {
      user: {
        username: "",
        password: "",
        nickname: ""
      }
    };
  },
  methods: {
    register() {
      console.log(this.user);
      if (
        /^1[35789]\d{9}$/.test(this.user.username) &&
        /^.{3,16}$/.test(this.user.password) &&
        this.user.nickname.length > 0
      ) {
        userRegister(this.user)
          .then(res => {
            console.log(res);
            if (res.data.message === "注册成功") {
              this.$toast.success(res.data.message);
              this.$router.push({ path: "/login" });
            } else {
              this.$toast.fial(res.data.message);
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}

.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}

.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}

.inputs {
  input {
    margin-bottom: 20px;
  }
}

.tips {
  text-align: right;
  margin-bottom: 20px;

  a {
    color: #3385ff;
  }
}
</style>